// 每个业务模块当中，对于Vuex来说，结构几乎是一样的
// 都包含 state actions mutations getters 
import request from '../../utils/request.js'
const state = {
	
	homeInfo:{},
	cardList:[],
}
const actions = {
	// 1获取主页面数据
	async getHomeInfoData({commit}){
		try{
			const result =await request({url:'/getIndexData'})
			console.log('home',result)
			commit('SET_HOME_INFO_DATA',result)
		}catch(e){
			//TODO handle the exception
			console.log(e)
		}
	},
	// 2.获取页面中导航里面的内容数据
	async getHomeCardListData({commit}){
		try{
			const result = await request({url:'/getIndexCateList'})
			console.log('hhh',result)
			commit('SET_HOMECARD_LIST_DATA',result)
		}catch(e){
			//TODO handle the exception
			console.log(e.message)
		}
	}
}
const mutations = {
	// 1.存储homeInfo数据，推荐模块中的数据
	SET_HOME_INFO_DATA(state,result){
		state.homeInfo = result
	},
	// 2.获取导航相关的数据
	SET_HOMECARD_LIST_DATA(state,result){
		state.cardList =result
	}
}
const getters = {
	navList(state){
	 return (state.homeInfo.kingKongModule || {}).kingKongList || []
	},

	sloganList(state){
		return state.homeInfo.policyDescList || []
	},
	floorsList(state){
		return state.homeInfo.categoryModule || []
	}
}
export default {
	namespaced: true,
	state,
	actions,
	mutations,
	getters
}